﻿using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.Tool.FileTools
{
    /// <summary>
    /// 写日志操作类
    /// </summary>
    public static class LogHelper
    {
        public static void Info(ILogger log, string temp, string msg, DateTime? time = null)
        {
            log?.Information((time ?? DateTime.Now).ToString("HH:mm:ss.fff") + $" [{temp}] " + msg);
        }
        public static void Error(ILogger log, string temp, string msg, Exception ex = null, DateTime? time = null)
        {
            if (ex == null)
            {
                log?.Error((time ?? DateTime.Now).ToString("HH:mm:ss.fff") + $" [{temp}] " + msg);
            }
            else
            {
                log?.Error((time ?? DateTime.Now).ToString("HH:mm:ss.fff") + $" [{temp}] " + msg, ex);
            }
        }
    }
}
